<template>
    <rx-dialog @handOk="onOk" @cancel="onCancel">
        <rx-layout>
            <div slot="center" style>
                <rx-fit>
                    <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                        <div class="table-page-search-wrapper">
                            <a-form layout="inline">
                                <a-row :gutter="24">
                                    <a-col :span="8">
                                        <a-form-item :label="i18n('form.templateName','模板名称')">
                                            <a-input :placeholder="i18n('form.templateName','请输入名称','input')" v-model="queryParam.Q_TEMPLATE_NAME__S_LK" />
                                        </a-form-item>
                                    </a-col>
                                    <a-col :span="8">
                                        <a-form-item  >
                                            <a-button type="primary" @click="$refs.table.loadData()" icon="search">
                                                {{$ti18('rxList.searchBtn','查询')}}
                                            </a-button>
                                        </a-form-item>
                                    </a-col>
                                </a-row>
                            </a-form>
                        </div>
                    </div>
                    <rx-grid
                        ref="table"
                        :allowRowSelect="true"
                        :multiSelect="false"
                        :columns="columns"
                        :defaultPageSize="10"
                        url="/api-form/form/core/formWordTemplate/query"
                        :queryParam="queryParam"
                        data-field="result.data"
                        :pageSizeOptions="['10','30','40']"
                        id-field="id"
                        :selectRowKeys="selectRowKeys"
                        @selectChange="onSelectChange"
                    >
                    <span slot="mode" slot-scope="{ text, record }">
                        <a-tag :color="modeMap[text].color">
                          <span>{{ modeMap[text].text }}</span>
                        </a-tag>
                    </span>
                    </rx-grid>
                </rx-fit>
            </div>
        </rx-layout>
    </rx-dialog>
</template>

<script>
import FormWordTemplateApi from '@/api/form/core/formWordTemplate'
import FormWordTemplateEdit from './FormWordTemplateEdit'
import {BaseList, RxFit, RxGrid, Util,RxDialog} from "@lowcode/jpaas-common-lib";

export default {
    name: 'FormWordTemplateDialog',
    mixins: [BaseList],
    components: {
        RxFit,
        RxDialog
    },
    props:["boDefId","templateId", "layerid","destroy"],
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 100,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.templateName','模板名称'), dataIndex: 'templateName', width: 100},
                {title: this.i18n('form.mode','模式'), dataIndex: 'mode', width: 100, scopedSlots: {customRender: 'mode'}},
                {title: this.i18n('form.fileName','文件名'), dataIndex: 'fileName', width: 100}
            ],
            component: FormWordTemplateEdit,
            comment: this.i18n('list.comment',"表单Word模板"),
            widthHeight: ['600px', '400px'],
            fitSearch: false,
            modeMap: {
                "on-line": {color: 'green', text: this.i18n('modeMap.online','在线')},
                "off-line": {color: 'blue', text: this.i18n('modeMap.offline','离线')},
            },
            selectRowKeys:[]
        }
    },
    created() {
        this.queryParam.Q_BO_ID__S_EQ=this.boDefId?this.boDefId:"";
        if(this.templateId){
            this.selectRowKeys.push(this.templateId);
        }
    },
    mounted() {
        if(this.templateId){
            this.$refs.table.selectRowKeys = [this.templateId];
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"wordTemplate",key);
        },
        getListByParams(parameter) {
            return FormWordTemplateApi.query(parameter)
        },
        onOk(vm){
            var node=this.$refs.table.getSelectedRow();
            if(!node){
                this.$message.warn(this.$ti18('rxMsa.masWarn.selectOneRecord',"请选择一行记录"));
                vm.loading=false;
                return ;
            }
            Util.closeWindow(this,'ok',node);
        },
        onCancel(){
            Util.closeWindow(this,'cancel');
        }
    }
}
</script>
<style scoped>

</style>

